from typing import Union
from fastapi_amis_admin.models import Field
from pydantic import BaseModel
from fastapi import HTTPException


class PageParams(BaseModel):
    page: int = Field(default=1, title="页码", description="页码")
    size: int = Field(default=10, title="每页条数", description="每页条数")
    params: dict = Field(default=None, title="查询参数", description="查询参数")


class PageResult(BaseModel):
    page: int = Field(default=1, title="页码", description="页码")
    size: int = Field(default=10, title="每页条数", description="每页条数")
    total: int = Field(default=0, title="总数", description="总数")
    list: object = Field(default=None, title="页码", description="分页数据列表")


class ApiResult(BaseModel):
    code: int = Field(default=200, description="状态码")
    msg: str = Field(default="", description="错误描述")
    data: object = Field(default=None, description="数据")


class respJsonBase(BaseModel):
    code: int
    msg: str
    data: Union[dict, list]


class DemoException(HTTPException):
    def __init__(self, err_code: int = 400, err_msg: str = ''):
        self.status_code = 200
        self.detail = ''
        self.err_code = err_code
        self.err_msg = err_msg
